/*
* Copyright (c) 2008-2011, Thomas Handorf
* 
* This file is part of libScopes.
* libScopes is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* libScopes is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public License
* along with libScopes.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifdef SCOPES_USEBOOSTSERIALIZATION
#include <boost/archive/text_oarchive.hpp> 
#include <boost/archive/text_iarchive.hpp> 
#endif // SCOPES_USEBOOSTSERIALIZATION
//#include "array.h"
#include "net.h"
#include <iostream> 
#include <sstream> 


int main(){
   /*
   c0+c1->c2,c3+c2->c4+c5,c1->c6
   */ 
   
   // Warning! the use of new VS() in the examples below leaks memory!!! the passed arrays need to be destroyed after setting
   //testing copy constructor and assignment
   Net n1;
   n1.addRea(new VS(2,(size_type[]){0,1}),new VS(1,(size_type[]){2}));
   Net n2=n1;
   n2.reaMask->put(0,0);
   if (n1.reaMask->at(0) == n2.reaMask->at(0)){
      printf("assingment failed; reaMasks still the same\n");
      abort();
   }
   n2.addRea(new VS(2,(size_type[]){3,2}),new VS(2,(size_type[]){4,5})); // this should copy the netstruct
   if (n1.numR()!=1 && n2.numR()!=2){
      printf("netstruct has not been copied\n");
      abort();
   }
   n1.print_matrix();
   n2.print_matrix();
   
   Net* net=new Net;
   net->addRea(new VS(2,(size_type[]){0,1}),new VS(1,(size_type[]){2}));
   net->print();
   net->addRea(new VS(2,(size_type[]){3,2}),new VS(2,(size_type[]){4,5}));
   net->print();
   net->replaceRea(2,new VS(1,(size_type[]){1}),new VS(1,(size_type[]){6}));
   net->print();
   size_type idx=net->addRea(new VS(0),new VS(1,(size_type[]){2})); // producing reaction
   printf("added rea %ld\n",idx);
   net->print();
   net->print_matrix();
   idx=net->addRea(new VS(1,(size_type[]){3}),new VS(1,(size_type[]){7}));
   net->setSubstrates(idx,new VS(1,(size_type[]){7}));
   net->setProducts(idx,new VS(1,(size_type[]){8}));
   net->setCatalysts(idx,new VS(1,(size_type[]){4}));
   net->setInhibitors(idx,new VS(1,(size_type[]){2}));
   net->setInhibited(idx,new VS(1,(size_type[]){7}));
   net->setPropagators(idx,new VS(1,(size_type[]){8}));
   if (net->succs(3)->find(idx)!=-1){
      printf("in 3 is still a successor\n");
      abort();
   }
   if (net->preds(4)->find(idx)!=-1){
      printf("in 4 is still a predecessor\n");
      abort();
   }
   if (net->succs(7)->find(idx)==-1 || net->succs(4)->find(idx)==-1 || net->succs(2)->find(idx)==-1){
      printf("in 7 4 2 are not successors\n");
      abort();
   }
   if (net->preds(8)->find(idx)==-1){
      printf("in 8 is not a predecessor\n");
      abort();
   }
   net->print();
   net->print_matrix();
   
   
   
   #ifdef SCOPES_USEBOOSTSERIALIZATION

   std::stringstream ss;   
   
   boost::archive::text_oarchive oa(ss); 
   oa << *net; 
   
   Net* net3=new Net;
   boost::archive::text_iarchive ia(ss); 
   ia >> *net3;
   net3->print();
   #endif // SCOPES_USEBOOSTSERIALIZATION
   
   return 0;
   }
   